package 分治;

public class FindMinAndMax {

    public static InitPair min_max(int[] a,int low,int high){
        InitPair pair = new InitPair();
        if (low > high - 2) {
            if (a[low] < a[high]) {
                pair.x = a[high];
                pair.y = a[low];
            }else{
                pair.x = a[low];
                pair.y = a[high];
            }
        }else{
            int mid = (low + high) / 2;
            InitPair p1 = min_max(a, low, mid);
            InitPair p2 = min_max(a, mid + 1, high);
            pair.x=p1.x>p2.x?p1.x:p2.x;
            pair.y=p1.y<p2.y?p1.y:p2.y;
        }
        return pair;
    }

    private static class InitPair {
        int x;
        int y;

        @Override
        public String toString() {
            return "InitPair{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }
    }

    public static void main(String[] args) {
        int[] arr = {3,6,7,8,2,0};
        System.out.println(min_max(arr, 0, arr.length-1));
    }
}
